package shayu.product.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import shayu.product.entity.SkuImagesEntity;
import shayu.product.entity.SkuInfoEntity;
import shayu.product.service.SkuInfoService;



/**
 * sku信息
 *
 * @author xiaoshayu
 * @email xiaoshayu@qq.copm
 * @date 2023-05-03 22:48:57
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    // 获取数据库最新价格数据
    @GetMapping("/{skuId}/price")
    public BigDecimal getPrice(@PathVariable("skuId")Long skuId){
        SkuInfoEntity byId = skuInfoService.getById(skuId);
        BigDecimal price = byId.getPrice();
        return price;
    }

    @RequestMapping("/{spuId}/list")
    public R getSkuBySpuId(@ PathVariable("spuId") Long spuId){
        List<SkuInfoEntity> data=skuInfoService.getSkuBySpuId(spuId);
        return R.ok().put("es",data);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageById(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@RequestParam("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
